package edu.ucsd.cse135.gas.action.chair;

import java.sql.Connection;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import edu.ucsd.cse135.gas.bean.chair.DecisionParameterBean;
import edu.ucsd.cse135.gas.logic.chair.Decision;
import edu.ucsd.cse135.gas.logic.support.Database;
import edu.ucsd.cse135.gas.resources.Constants;

public class DecisionAction extends DispatchAction {

	public ActionForward accept(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		
			DecisionParameterBean decisionParameter = (DecisionParameterBean)form;
			
			String applicant = decisionParameter.getApplicant();
			applicant = applicant.replace("%40", "@");
			
			request.setAttribute("mail", decisionParameter.getReviewer());
			request.setAttribute("section", decisionParameter.getSection());
			
			Decision.accept(applicant);
			
			return mapping.findForward(Constants.SUCCESS);
	}
	
	public ActionForward reject(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		
			DecisionParameterBean decisionParameter = (DecisionParameterBean)form;
			
			String applicant = decisionParameter.getApplicant();
			applicant = applicant.replace("%40", "@");
			
			request.setAttribute("mail", decisionParameter.getReviewer());
			request.setAttribute("section", decisionParameter.getSection());
			
			Decision.reject(applicant);
			
			return mapping.findForward(Constants.SUCCESS);
	}

	public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
	
			DecisionParameterBean decisionParameter = (DecisionParameterBean)form;
			
			String applicant = decisionParameter.getApplicant();
			applicant = applicant.replace("%40", "@");
			
			request.setAttribute("mail", decisionParameter.getReviewer());
			request.setAttribute("section", decisionParameter.getSection());
		
			Decision.cancel(applicant);
			
			return mapping.findForward(Constants.SUCCESS);
	}
}
